package com.acme.team3.chat;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.acme.team03.messages.TextMessage;
import com.acme.team03.net.server.ConnectionDispatcher;

public class HistoryCommandHandler implements CommandHandler {

	private static Logger log = Logger.getLogger(HistoryCommandHandler.class.getName());
	private ConnectionDispatcher connDispatcher;
	
	public HistoryCommandHandler(ConnectionDispatcher connDispatcher) {
		this.connDispatcher = connDispatcher;
	}

	@Override
	public void handle(Command cmd) {
		try {
			log.log(Level.INFO, "History requested.");
			TextMessage msg = new TextMessage("Hist");
			msg.setProperty("ID", connDispatcher.getAllConnections().get(0).getID());
			connDispatcher.getAllConnections().get(0).sendMessage(msg);
		} catch (IOException e) {
			log.log(Level.SEVERE, e.toString());
		}
	}

}
